//
//  YWImageService.m
//  百布业务
//
//  Created by chenbinghua on 09/11/15.
//  Copyright © 2015年 陈炳桦. All rights reserved.
//

#import "YWImageService.h"

@implementation YWImageService


//对图片尺寸进行压缩--
+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    
    // Tell the old image to draw in this new context, with the desired
    // new size
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // End the context
    UIGraphicsEndImageContext();
    
    // Return the new image.
    return newImage;
}

//压缩图片
+ (NSData*)compressTheBBImage:(UIImage*)image
{
    //设置image的尺寸
    CGSize imagesize = image.size;
    //如果尺寸已经小于1000了,不再进行缩放
    if(imagesize.height<=1000||imagesize.width<=1000)
    {
        ;
    }
    else
    {
        imagesize.height =imagesize.height/3.0f;
        imagesize.width =imagesize.width/3.0f;
    }
    
    image = [self imageWithImage:image scaledToSize:imagesize];
    
    NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
    
    return imageData;
}



@end
